﻿using System;
using System.Collections.Generic;
using System.Text;

namespace HW
{
    /// <summary>
    /// 提供封装好的基础方法
    /// </summary>
    public static class API
    {
        public static T[] ForEach<T>(this T[] array, Action<T> func)
        {
            foreach (var t in array)
            {
                func(t);
            }
            return array;
        }

        public static T[] ForEach<T>(this T[] array, Action<T, int> func)
        {
            for (var i = 0; i < array.Length; i++)
            {
                func(array[i], i);
            }
            return array;
        }

        public static V GetValue<K, V>(this IDictionary<K, V> dic, K key, V def)
        {
            if (dic.TryGetValue(key, out var v))
                return v;
            else
                return def;

        }
    }
}
